//
//  BHCircleDetailNavigationBar.swift
//  BigHealth
//
//  Created by 蔺百好 on 2021/7/12.
//

import UIKit
protocol BHCircleDetailNavigationBarDelegate {
    func didSelectNavigationBarType(type: Int)
}

class BHCircleDetailNavigationBar: UIView {
    
    var delegate: BHCircleDetailNavigationBarDelegate?
    
    
    @IBOutlet weak var more_btn: UIButton!
    @IBOutlet weak var headerIconBtn: UIButton!
    
    @IBOutlet weak var name_label: UILabel!
    
    @IBOutlet weak var attensionBtn: UIButton!
    
    var model: BHCircleDetailInfoModel! {
        didSet {
            self.name_label.text = model.userName
            self.headerIconBtn.sd_setImage(with: URL.init(string: model.userAvatar), for: .normal, placeholderImage: nil, options: .retryFailed, context: nil)
            self.attensionBtn.isSelected = model.attentionFlag == 1
            let selfPublish = model.userId == BHMeUserInfoModel.shared.userId
            
            self.attensionBtn.isHidden = selfPublish
            
//            self.more_btn.setImage(UIImage.init(named: selfPublish == true ? "bh_com_nav_del_black":"bh_com_nav_report_black"), for: .normal)
        
        }
    }
    
    
    static func loadFromXib() -> BHCircleDetailNavigationBar {
        let viewArray = Bundle.main.loadNibNamed("BHCircleDetailNavigationBar", owner: nil, options: nil)
        let view: BHCircleDetailNavigationBar = viewArray![0] as! BHCircleDetailNavigationBar
        return view
    }
    override func awakeFromNib() {
        super.awakeFromNib()
       
        self.headerIconBtn.addLayerCorner(14, 0, .color_34CE98)
        self.attensionBtn.addLayerCorner(12, 0.5, .color_34CE98)
        
        self.headerIconBtn.addBtnAction(action: {[weak self] (_) in
            self?.delegate?.didSelectNavigationBarType(type: 3)

        }, for: .touchUpInside)
        
        self.name_label.addViewAction {[weak self] (_) in
            self?.delegate?.didSelectNavigationBarType(type: 3)
        }
    }
    
    
    @IBAction func back_actAction(_ sender: Any) {
        self.delegate?.didSelectNavigationBarType(type: 0)
    }
    
    
    @IBAction func more_actAction(_ sender: Any) {
        self.delegate?.didSelectNavigationBarType(type: 1)

    }
    
    
    @IBAction func attensionAct(_ sender: UIButton) {
        self.delegate?.didSelectNavigationBarType(type: 2)
        
    }
}
